package org.mockfu.testng;

import org.mockfu.Injection;
import org.mockfu.MockControl;
import org.testng.IHookCallBack;
import org.testng.IHookable;
import org.testng.ITestResult;


/**
 * Automatic mock verifier for TestNG. Subclass this from a test class to enable for all tests in
 * that class. This runner will also automatically eject any injections that have not yet been
 * ejected.
 */
public class Verifier implements IHookable
{

    public void run(IHookCallBack callback, ITestResult testResult)
    {
        try
        {
            MockControl<Verifier> verifier = MockControl.of(Verifier.class);
            callback.runTestMethod(testResult);
            verifier.verifyAll();
        }
        finally
        {
            Injection.ejectAll();
        }
    }

}
